<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script th:src="@{/main/layuimini/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
    <script th:src="@{/main/js/jquery-2.1.3.min.js}" charset="utf-8"></script>
    <link rel="stylesheet" th:href="@{/main/layuimini/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/main/layuimini/css/public.css}" media="all">
    <script th:src=" @{/main/js/axios.min.js}"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <!--        <div class="layui-input-block">-->
        <!--            <input type="hidden" name="action" value="addHall"-->
        <!--                   class="layui-input">-->
        <!--        </div>-->
        <label class="layui-form-label required">演出厅名称</label>
        <div class="layui-input-block">
            <input type="text" id="hname" name="hname" lay-verify="required|name" lay-reqtext="演出厅名不能为空"
                   placeholder="请输入演出厅名称" value=""
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">座位行数</label>
        <div class="layui-input-block">
            <input type="text" id="hrow" name="hrow" lay-verify="required|number" lay-reqtext="座位行数不能为空"
                   placeholder="请输入座位行数"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">座位列数</label>
        <div class="layui-input-block">
            <input type="text" id="hcol" name="hcol" lay-verify="required|number" lay-reqtext="座位列数不能为空"
                   placeholder="请输入座位列数"
                   value="" class="layui-input">
            <!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">演出厅描述</label>
        <div class="layui-input-block">
            <textarea id="hdesc" name="hdesc" class="layui-textarea" placeholder="请输入演出厅描述"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" id="submit" lay-submit lay-filter="saveBtn">立即提交</button>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        form.verify({
            name: [
                /^[\u4e00-\u9fa5]{3,8}[0-9]{0,3}$/,
                '至少有三个汉字且数字最多为3个只能在结尾'
            ]
        })

        //监听提交
        function hint(data) {
            layer.msg(data, {
                icon: 1,
                time: 1000,
                end: function () {
                    parent.refresh();//刷新到表格
                    // 关闭弹出层
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }
            });
            return false;
        }

        function hintError(data) {
            layer.msg(data, {
                icon: 5,
                time: 1000,
                end: function () {
                    $("#submit").removeAttr("disabled", "disabled").removeClass("layui-btn-disabled");
                }
            });
            return false;
        }

        form.on('submit(saveBtn)', function (data) {
            $("#submit").attr("disabled", "disabled").addClass("layui-btn-disabled");
            var url = '/hall/addHall';
            axios.post(
                url,
                data.field
            ).then(function (response) {
                var data = response.data;
                if (data == "添加成功")
                    hint(data)
                else
                    hintError(data);
            })
            return false;
        })
    });
</script>
</body>
</html>